import { Almanac } from "@/utils/almanac";
import request from "@/utils/request"
import {ImageData,createCanvas} from 'canvas'
import { Message, MessageType } from "mirai-ts";

interface signInfo{
  "shipId": 295,
  "shipName": "Alexander Nevsky",
  "chnShipName": "亚历山大·涅夫斯基",
  "nation": "ussr",
  "should": "心态炸裂器",
  "taboo": "碎碎平安 捏不死鸡",
  "shipGrade": 10,
  "shipType": "Cruiser",
  "wowsId": "4074681808",
  "shipIdStr": "PRSC210",
  "image": "https://glossary-wows-global.gcdn.co/icons//vehicle/medium/PRSC210_e3a29c84d422c0ea98f6f3f34f61a86847ee5f83e0358557410f9f288757d148.png",
  "description": "最後一項為蘇聯海軍開發的大火炮艦艇計畫（84 計畫）。此巡洋艦的主武裝由獨特的火炮系統 — 180 毫米兩用炮所組成。",
  "createTime": "2020-07-23T12:13:28.000+0000",
  "updateTime": "2021-05-21T02:38:28.000+0000"
}



/**
 * 签到功能
 * @param qq 
 */
export async function sign(almanac:Almanac,msg:MessageType.GroupMessage){
  let messageChain: MessageType.MessageChain = [Message.At(msg.sender.id)]
  await request.get('/wowsInfoToBot/botWowsSign',{qq:msg.sender.id}).then((response:any) => {


    response = response.data
    messageChain.push(Message.Plain(`\n今日幸运船：${response.chnShipName}`))
    messageChain.push(Message.Image(null, response.image,null))
    messageChain.push(Message.Plain(`\n${almanac.getAlmanac().nongli}`))
    messageChain.push(Message.Plain(`\n${almanac.getAlmanac().suici}`))
    messageChain.push(Message.Plain(`\n宜：${response.should}`))
    messageChain.push(Message.Plain(`\n忌：${response.taboo}`))
  }).catch(error=>{
    console.log(error)
    messageChain.push(Message.Plain(`\n出了点状况`))
  });
  return messageChain


  // 创建canvas
  
  // const canvas = createCanvas(375, 667)
  // const context = canvas.getContext('2d')
  // // 底色涂白
  // context.fillStyle = '#ffffff'
  // context.fillRect(0, 0, 375, 667)

  // let img = new Image();   // 创建img元素
  // img.src = 'myImage.png'; // 设置图片源地址
  // img.onload = function(){
  //   let ratio = 435/256
  //   300/ratio
  //   context.drawImage(img,75/2,20,300/ratio,300*ratio);
  //   const buffer = canvas.toBuffer('image/png')
  //   fs.writeFileSync('G:/temp/test.png', buffer)
  // }
}